package com.awspaas.user.apps.cpq.controller;

import java.util.ArrayList;
import java.util.List;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;

public class CPQ_GetTemplateSystemPriceWeb {

	public String getTemplateSystemPrice(UserContext userContext, String bindId) {
		try {
			String sql="select XTMC,XTMH,PX,SUM(ZCLF) as CLF, SUM(ZCGF) as CGF,"
					+ "SUM(ZGSF) as RGF,SUM(ZWX) as WX,SUM(ZJ) as DJ "
					+ "from  BO_EU_CPQ_TEMPLATE_PRICE_MODULE "
					+ "where  BINDID=? GROUP BY XTMC ";
			//删除原有的单栋设备明细信息数据
		List<BO> bos=	SDK.getBOAPI().query("BO_EU_CPQ_TEMPLATE_PRICE_SYSTEM").bindId(bindId).list();
		if(bos.size()>0) {
			SDK.getBOAPI().removeByBindId("BO_EU_CPQ_TEMPLATE_PRICE_SYSTEM", bindId);
		}
			List<RowMap> maps=DBSql.getMaps(sql, new Object[] {bindId});
			if(maps.size()>0) {
				List<BO> lists=new ArrayList<BO>();
				for (RowMap rowMap : maps) {
					BO bo=new BO();
					bo.set("XTMC", rowMap.getString("XTMC"));
					bo.set("XTMH", rowMap.getString("XTMH"));
					bo.set("PX", rowMap.getString("PX"));
					bo.set("CLF", rowMap.getString("CLF"));
					bo.set("RGF", rowMap.getString("RGF"));
					bo.set("WXWG", rowMap.getString("WX"));
					bo.set("CGF", rowMap.getString("CGF"));
					bo.set("DJ", rowMap.getString("DJ"));
                    lists.add(bo);
				}
				SDK.getBOAPI().create("BO_EU_CPQ_TEMPLATE_PRICE_SYSTEM", lists, bindId, userContext.getUID());
			}
			
			ResponseObject ro = ResponseObject.newOkResponse();
			   return ro.toString();
		} catch (Exception e) {
			throw e;
		}
		
	}

}
